//
//  ViewController.m
//  04.汤姆猫
//
//  Created by 张青花 on 15/7/21.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

/**
 tom猫的图片
 */
@property (weak, nonatomic) IBOutlet UIImageView     *tomImage;

@end

@implementation ViewController


- (void) gogogoWithnumber:(NSInteger) number AndImageName:(NSString *) imageName
{
    
    if (self.tomImage.isAnimating) {
        return;
    }
    
    NSMutableArray *arrayImage = [NSMutableArray array];
    
    for (int i=0; i<number; i++) {
       NSString *imageStr = [NSString stringWithFormat:@"%@_%02d",imageName,i];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:imageStr ofType:@".jpg"];
        
        
        UIImage *image  =[UIImage imageWithContentsOfFile:path];
        [arrayImage addObject:image];
        
    }

    self.tomImage.animationImages      = arrayImage;

    self.tomImage.animationRepeatCount = 1;

    self.tomImage.animationDuration    = number*0.05;

    [self.tomImage startAnimating];

    [self performSelector:@selector(clearimages) withObject:nil afterDelay:5];
}

- (void) clearimages
{
    self.tomImage.animationImages =nil;
}

- (IBAction)eat {
    
    
    [self gogogoWithnumber:40 AndImageName:@"eat"];
}
- (IBAction)drink {
    
    [self gogogoWithnumber:81 AndImageName:@"drink"];

}

- (IBAction)niao {
    [self gogogoWithnumber:12 AndImageName:@"cymbal"];

}
- (IBAction)fart {
    [self gogogoWithnumber:28 AndImageName:@"fart"];

}
- (IBAction)pie {
     [self gogogoWithnumber:24 AndImageName:@"pie"];
}
- (IBAction)scratch {
     [self gogogoWithnumber:56 AndImageName:@"scratch"];
}
- (IBAction)knockout {
     [self gogogoWithnumber:81 AndImageName:@"knockout"];
}
- (IBAction)footLeft {
    [self gogogoWithnumber:30 AndImageName:@"footLeft"];
}
- (IBAction)footRight {
    [self gogogoWithnumber:30 AndImageName:@"footRight"];

}
- (IBAction)stomach {
    [self gogogoWithnumber:34 AndImageName:@"stomach"];
}

- (IBAction)angry {
    [self gogogoWithnumber:26 AndImageName:@"angry"];
}

@end
